package com.njupt.simulation.utils;

import com.njupt.simulation.entity.LeoSatellite;
import com.njupt.simulation.entity.Station;
import java.util.ArrayList;
import java.util.List;

import static com.njupt.simulation.utils.CalculateAER.calculateEL;

public class IsVisibility {
    /**
     * 判断通过星历生成的低轨卫星是否在地球站的可视范围内
     * @param leoSatellites 低轨卫星列表
     * @param station 地球站
     * @param datatime 当前时刻时间
     */
    public static void tleleoisvisibility(List<LeoSatellite> leoSatellites, Station station, String datatime) {

        List<LeoSatellite> leosatelliteselect = new ArrayList<>();
        List<LeoSatellite> leosatelliteother = new ArrayList<>();
        for (LeoSatellite satellite : leoSatellites) {

            double[] stationcoordinate = new double[]{station.getLongitude(), station.getLatitude(), station.getHeight()};

            double[] leosatellitecoordinate = TLEtoCoordinate.tletocoordinate(satellite,datatime);

            //计算当前时刻下的低轨卫星和低轨地球站之间的俯仰角
            double ele = calculateEL(stationcoordinate, leosatellitecoordinate);
            //筛选出可视范围内的低轨卫星
            if ((90 - ele) >= station.getElevation()) {
                // 添加可视范围内的卫星加到可视卫星的列表中
                leosatelliteselect.add(satellite);
            } else if (ele > (90 - station.getElevation()) && ele < 90) {
                //不可视但在地平线以上
                leosatelliteother.add(satellite);
            }
        }
    }

}
